<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>留言板</title>
<%@ include file="/WEB-INF/layouts/comm/datatables.jsp"%>
<%@ include file="/WEB-INF/layouts/comm/kindeditor.jsp"%>
<%@ include file="/WEB-INF/layouts/comm/form.jsp"%>
</head>
<body>
	<div class="mod_header">
		<div class="title">
			<h2 id="h_title">留言板</h2>
		</div>
	</div>
	<ol class="breadcrumb">
		<li><a href="#">功能设置</a></li>
		<li class="active">留言板</li>
	</ol>
	<div class="mod_basic">
		<div class="title">
			<h3>留言板</h3>
		</div>

		<div class="content">
			<div class="sub_content_table_tool">
				<div class="sub_header">
					<div class="sub_bar">
						关键字：留言板 <br><br>
						<a href="${ctx}/webCustomer/words/config/add"
							class="btn btn-primary "><i class="fa fa-plus"></i> 留言板设置</a>
					</div>
				</div>
			</div>
			<div id="examItem_content">
				<div class="sub_content_table">
					<table
						class="table table-striped table-bordered table-hover datatable"
						id="datatable">
						<thead>
							<tr>
								<th width="140">学员姓名</th>
								<th>留言内容</th>
								<th>留言时间</th>
								<th>回复内容</th>
								<th width="140">操作</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
	<footer_body> <script id="tpl"
		type="text/x-handlebars-template">
	    {{#each func}}
	    <button type="button" class="btn btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>
	    {{/each}}
	</script> <script>
		base.menu.active('menu_208');
		var tpl = $("#tpl").html();
		//预编译模板
		var template = Handlebars.compile(tpl);

		var table = base.datatable.table({
			tableid : '#datatable',
			aoColumns : [ {
				"data" : "name"
			}, {
				"data" : "content"
			}, {
				"data" : "createTime"
			}, {
				"data" : "reback"
			}, {
				"data" : "id"
			} ],
			columnDefs : [ {
				targets : 4,
				render : function(a, b, c, d) {
					var context = {
						func : [ {
							"name" : "修改回复",
							"fn" : "daWin(" + c.id + ")",
							"type" : "danger"
						}, {
							"name" : "删除",
							"fn" : "del(" + c.id + ",'" + c.name + "')",
							"type" : "default"
						} ]
					};
					var html = template(context);
					return html;
				}
			} ],
			url : "${ctx}/webCustomer/words/data?rand=" + Math.random()
		});

		function daWin(id) {
			base.dialog.win({
				title : "编辑回复",
				msg : $('<div></div>').load(
						'${ctx}/webCustomer/words/reback?id=' + id + '&rand='
								+ Math.random()),
				buttons : [ {
					label : '保存编辑',
					cssClass : 'btn-primary',
					action : function(dialogItself) {
						base.ajax.post({
							url : '${ctx}/webCustomer/words/save',
							data : {
								id : id,
								reback : $('#reback').val()
							},
							success : function(json) {
								if (json.data == true) {
									base.dialog.alert({
										msg : "编辑成功",
										callback : function() {
											rload();
											dialogItself.close();
										}
									});
								} else {
									base.dialog.alert({
										title : '错误',
										msg : "系统错误"
									});
								}
							}
						});
					}
				}, {
					label : '删除回复',
					cssClass : 'btn-warning',
					action : function(dialogItself) {
						base.ajax.post({
							url : '${ctx}/webCustomer/words/save',
							data : {
								id : id,
							},
							success : function(json) {
								if (json.data == true) {
									base.dialog.alert({
										msg : "删除成功",
										callback : function() {
											rload();
											dialogItself.close();
										}
									});
								} else {
									base.dialog.alert({
										title : '错误',
										msg : "系统错误"
									});
								}
							}
						});
					}
				}, {
					label : '关闭',
					action : function(dialogItself) {
						dialogItself.close();
					}
				} ]
			});
		}
		function del(id, name) {
			base.dialog.confirm({
				msg : "是否要删除[" + name + "]",
				callback : function(result) {
					if (result) {
						base.ajax.get({
							url : '${ctx}/webCustomer/words/del?id=' + id,
							success : function(json) {
								if (json.data == true) {
									base.dialog.alert({
										msg : "删除成功",
										callback : function() {
											rload();
										}
									});
								} else {
									base.dialog.alert({
										title : '错误',
										msg : "系统错误"
									});
								}
							}
						});
					}
				}
			});
		}

		function rload() {
			base.datatable.reloadAjax({
				url : "${ctx}/webCustomer/words/data?rand=" + Math.random()
			});
		}
	</script> </footer_body>
</body>
</html>